import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';

export default {
  /**
   * 获取礼品联系人列表数据
   * @param {String} url
   */
  getListData(url) {
    return new Promise((resolve, reject) => {
      const res = httpFetch.get(`${config.baseUrl}/api/market/marketContacts/getMarketContacts${url}`).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });

    });
  },
  /**
   * 新增一条礼品联系人信息记录
   * @param {Object} data
   */
  addRecord(data) {
    return new Promise((resolve, reject) => {
      const res = httpFetch.post('/api/market/marketContacts/saveMarketContacts', { ...data }).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    });
  },
  /**
   * 导出礼品联系人信息记录
   * @param {Object} data
   */
  exportData() {
    return new Promise((resolve, reject) => {
      const res = httpFetch.get(`${config.baseUrl}/api/common/download/by/command?all=false&page=0&size=10`, {}, {}, {responseType: 'arraybuffer'}).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    });
  }, /**
  * 获取区域市场维护列表数据
  * @param {String} url
  */
   getExtraListData (url) {
       return new Promise((resolve, reject) => {
           const res = httpFetch.get(`${config.baseUrl}/api/market/marketCompany/queryAll?size=100&page=0${url}`).then((res) => {
             resolve(res);
           }).catch((err) => {
             errorMessage(err.response);
             reject(err.response);
           });
       });
 },

  /**
   * 获取市场列表
   * @param {String} url
   */
  getMarketListData (url) {
    return new Promise((resolve, reject) => {
      const res = httpFetch.get(`${config.baseUrl}/api/company/search/getAreaOrMarket?areaOrMarketFlag=2&size=100&page=0${url}`).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    });
  },

//条件查询公司
getCompaniesByOptions(params){
  return new Promise((resolve, reject) => {
    httpFetch.get(config.baseUrl + '/api/company/by/term',params)
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        errorMessage(err.response);
        reject(err);
      })
  })
},
/**
   * 更新一条信息记录
   * @param {Object} data
   */
  updateData(data) {
    return new Promise((resolve, reject) => {
      const res = httpFetch.put('/api/market/marketContacts/updateMarketContacts', { ...data }).then((res) => {
        resolve(res);
      }).catch((err) => {
        errorMessage(err.response);
        reject(err.response);
      });
    });
  },
//根据ID删除礼品联系人
deleteGiftContact(ID) {
  return new Promise((resolve, reject) => {
    httpFetch.delete(`${config.baseUrl}/api/market/marketContacts/deleteMarketContacts?id=${ID}`)
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        errorMessage(err.response);
        reject(err);
      })
  })
},
//查询网点
getOutlets() {
  return new Promise((resolve, reject) => {
    httpFetch.get(`${config.baseUrl}/api/custom/enumerations/9e950622-b426-41b8-8fc5-8b14a2ba3ca8`)
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        errorMessage(err.response);
        reject(err);
      })
  })
},
};
